package com.operator.Activitys.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.operator.Activitys.R;
import com.operator.Activitys.adapter.base.BaseRecyclerViewAdapter;
import com.operator.Activitys.bean.TransferList;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 项目名称：金泽云 手机app
 * 类描述：转账记录 适配器
 * 创建人：张飞祥
 * 创建时间：2018/5/21 13:21
 * 修改人：张飞祥
 * 修改时间：2018/5/21 13:21
 * 修改备注：
 */
public class TransferListAdapter extends BaseRecyclerViewAdapter {

    //上下文
    private Context mContext;
    //数据集合
    private List<TransferList> mList;

    public TransferListAdapter(Context mContext, List<TransferList> mList) {
        super(mContext, mList);
        this.mContext = mContext;
        this.mList = mList;
    }


    @Override
    protected int getLayoutItemResId() {
        return R.layout.item_transfer_list;
    }


    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
        if (viewHolder instanceof TransferViewHolder) {

            //TODO 获取充值记录 viewHolder
            final TransferViewHolder holder = (TransferViewHolder) viewHolder;
            //TODO  将数据保存在itemView的Tag中，以便点击时进行获取
            holder.itemView.setTag(position);
            //TODO  获取数据源 第 i 个 实体数据
            TransferList transferList = mList.get(position);

            /**
             * 设置数据源
             */
            //充值时间
            holder.tvItemTransferTime.setText(transferList.getCreateTime());

            //TODO 转账 type （转入、转出）
            if ("入账".equals(transferList.getType())){
                //转入店铺
                holder.tvItemTransferName.setText(transferList.getFromStoreName());
                //转入 type
                holder.tvItemTransferType.setText(transferList.getType());
                //转入金额
                holder.tvItemTransferMoney.setText("+ " + transferList.getMoney() + "元");
                //设置 转入金额 字体颜色
                holder.tvItemTransferMoney.setTextColor(Color.parseColor("#6699ff"));
            }else{
                //转出店铺
                holder.tvItemTransferName.setText(transferList.getToStoreName());
                //转出 type
                holder.tvItemTransferType.setText(transferList.getType());
                //转出金额
                holder.tvItemTransferMoney.setText("- " + transferList.getMoney() + "元");
                //设置 转出金额 字体颜色
                holder.tvItemTransferMoney.setTextColor(Color.parseColor("#ff0000"));
            }
        }
    }

    @Override
    public RecyclerView.ViewHolder getViewHolder(View view) {
        return new TransferViewHolder(view);
    }

    /**
     * ViewHolder
     */
    public class TransferViewHolder extends RecyclerView.ViewHolder {

        //转账时间
        @Bind(R.id.tv_item_transfer_time)
        TextView tvItemTransferTime;
        //转账店铺名称
        @Bind(R.id.tv_item_transfer_name)
        TextView tvItemTransferName;
        //转账type
        @Bind(R.id.tv_item_transfer_type)
        TextView tvItemTransferType;
        //转账金额
        @Bind(R.id.tv_item_transfer_money)
        TextView tvItemTransferMoney;

        public TransferViewHolder(View itemView) {
            super(itemView);
            //绑定控件
            ButterKnife.bind(this, itemView);
            //item 适配
            AutoUtils.autoSize(itemView);
        }
    }
}
